var storageClass = function() {
    describe('存储类型相关操作', function () {
        let key = 'demo.txt';
        let file = blob({ size: 1024 * 1024 * 5 });
        before('上传文件', function (done) {
            this.timeout(10000);
            ks3.putObject({
                key,
                file
            }).then(res => {
                should.not.exist(res.error);
                data.statusCode.should.be.equal(200);
                done()
            })
        })
        after('删除文件', function (done) {
            this.timeout(2000);
            ks3.delObject({
                key
            }).then(res => {
                should.not.exist(res.error);
                data.statusCode.should.be.equal(204);
                done()
            })
        })
        describe('设置文件的存储类型为STANDARD', function () {
            it('设置文件的存储类型为STANDARD', function (done) {
                this.timeout(2000);
                ks3.modifyStorageClass({
                    key,
                    storageClass: 'STANDARD'
                }).then(res => {
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取文件的存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = data.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    (object.Key === key && object.StorageClass === 'STANDARD').should.be.ok;
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
        })
        describe('解冻存储类型为STANDARD的文件', function () {
            it('针对非归档类型的文件提交解冻操作,则返回400', function (done) {
                this.timeout(2000);
                ks3.restoreObject({
                    key,
                }).then(res => {
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(400);
                    done();
                })
            })
        })
        describe('设置文件的存储类型为STANDARD_IA', function () {
            it('设置文件的存储类型为STANDARD_IA', function (done) {
                this.timeout(2000);
                ks3.modifyStorageClass({
                    key,
                    storageClass: 'STANDARD_IA'
                }).then(res => {
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取文件的存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = data.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    (object.Key === key && object.StorageClass === 'STANDARD_IA').should.be.ok;
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
        })
        describe('通过请求头设置文件的存储类型为ARCHIVE', function () {
            it('通过请求头设置文件的存储类型为ARCHIVE,请求头中的值会覆盖掉参数中的值', function (done) {
                this.timeout(2000);
                ks3.modifyStorageClass({
                    key,
                    storageClass: 'ARCHIVE',
                    headers: {
                        'x-kss-storage-class': 'ARCHIVE'
                    }
                }).then(res => {
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
            it('获取文件的存储类型', function (done) {
                this.timeout(2000);
                ks3.listObjects({
                    prefix: key
                }).then(res => {
                    let contents = data.body.ListBucketResult.Contents;
                    let object;
                    if (contents instanceof Array) {
                        object = contents.find((item) => item.Key === key);
                    } else {
                        object = contents;
                    }
                    (object.Key === key && object.StorageClass === 'ARCHIVE').should.be.ok;
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(200);
                    done();
                })
            })
        })
        describe('解冻存储类型为ARCHIVE的文件', function () {
            it('对归档Object第一次调用RestoreObject接口,则返回202', function (done) {
                this.timeout(2000);
                ks3.restoreObject({
                    key,
                }).then(res => {
                    should.not.exist(res.error);
                    data.statusCode.should.be.equal(202);
                    done();
                })
            })
            it('如果已经成功调用过RestoreObject接口,且Object仍处于解冻中,再次调用时返回409', function (done) {
                this.timeout(2000);
                ks3.restoreObject({
                    key,
                }).then(res => {
                    should.not.exist(data);
                    res.error.statusCode.should.be.equal(409);
                    done();
                })
            })
        })
    })
}